﻿using System;
using System.Web.Configuration;

namespace TestWebApplication.Models.Config
{
    public class ConfigManager
    {
        private static ConfigManager instance;
        private readonly IEmailNotificationServiceConfig emailNotificationServiceConfig;
        private readonly bool generateServerExceptionMode;
        private readonly string connectionString;
        
        protected ConfigManager()
        {
            emailNotificationServiceConfig = (EmailNotificationServiceConfig)WebConfigurationManager
                    .GetSection("EmailNotificationServiceConfig");

            generateServerExceptionMode = Convert.ToBoolean(
                WebConfigurationManager.AppSettings["GenerateServerExceptionMode"]);

            connectionString = WebConfigurationManager
                .ConnectionStrings["DbConnectionString"].ConnectionString;
        }

        public static ConfigManager GetInstance()
        {
            if (instance == null)
            {
                instance = new ConfigManager();
            }

            return instance;
        }

        public bool GenerateServerExceptionMode
        {
            get { return generateServerExceptionMode; }
        }

        public IEmailNotificationServiceConfig EmailNotificationServiceServiceConfig
        {
            get { return emailNotificationServiceConfig; }
        }

        public string ConnectionString
        {
            get { return connectionString; }
        }
        
    }
}